from nltk import load_parser

def translate(sentence):
    parser = load_parser('file:grammar.fcfg', trace=0)
    tokens = sentence.split()
    trees = parser.nbest_parse(tokens)
    if len(trees) == 0:
        print 'Failed to parse: ' + sentence
        raise Exception()
    tree = trees[0]
#    print tree
    fol = tree.node['SEM']
#    print fol
    sen_type = tree.node.get('TYPE', 'fact')
    return str(fol), sen_type
